package com.example.webchar.webchar.mapper.master;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.webchar.webchar.pojo.ChapterName;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: wechat-web-is-my
 * @description
 * @author: 郭逍
 * @create: 2021/8/21 10:57
 **/
@Mapper
@Service
public interface ChapterNameMaster extends BaseMapper<ChapterName> {
    /**
     * 往表chapter_name中插入章节名称和主表id
     *
     * @param list
     */
    @Insert("<script>insert into chapter_name(chapter_name,novel_id) values" +
            "<foreach collection=\"list\" item=\"item\" index=\"index\"  separator=\",\"> " +
            "(#{item.chapterName},#{item.novelId})" +
            "</foreach></script>")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insChapterList(@Param("list") List<ChapterName> list);

    /**
     * 根据小说id删除小说的全部信息
     *
     * @param novelId 小说的简介id
     */
    @Delete("delete from chapter_name where novel_id=#{novelId}")
    void deleteChapterNameByNovelId(@Param("novelId") Integer novelId);

}
